/**
 * 
 */

/**
 * 
 */

var url;//全局URL
var orderId;//订单ID
var tripStatus;//行程状态
var payInfo;//支付参数
$(document).ready(function() {
	$.showLoading();
	getMyTrips();
	//getTrip();
});

$(document).on("click", "#data-list .info-content", function(e) {
	//获取订单的ID
	var tripId = $(this).find(".orderId").eq(0).val();
	window.location.href = "infoCenter.html?tripId=" + tripId;
});

//防止事件冒泡
$(document).on("click",".driverTel",function(e){
	e.stopPropagation();//终止事件冒泡  
});

//加载更多触发
$(document).on("click",".getMore",function(){
	$.showLoading();
	pageIndex += 1;
	getMyTrips();
});

//获取客户端IP地址
function clientIp(){
	var ipAddress="175.102.15.202";
	var url = 'http://chaxun.1616.net/s.php?type=ip&output=json&callback=?&_='+Math.random(); 
    $.getJSON(url,false,function(data){
	        ipAddress = data.Ip; 
	});
    
    return ipAddress;
	
}

$(document).on("click",".pay_money",function(){
	var openId=getParam(location.href,"openid");//用户ID
	var orderId=$(this).attr("orderId");//订单号码
	var finalCost=$(this).attr("finalCost");//支付费用
	var userId = $(this).attr("userId");
	var ipAddress = clientIp();
	
	//订单系统的支付参数
	$.ajax({
		url:"/Wchat/pay/payParam.do",
		data:{openid:openId,orderId:orderId,userId:userId,clientIp:ipAddress},
		success:function(json){
			
			if(json.success == true){
				payInfo=json;			}else{
				alert("支付参数不对");
				return;
			}
			
			if (typeof WeixinJSBridge == "undefined"){
			   if( document.addEventListener ){
			       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
			   }else if (document.attachEvent){
			       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
			       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			   }
			   alert("初始化失败");
			}else{
			   onBridgeReady();
			}
		}
	});
	
	if (typeof WeixinJSBridge == "undefined"){
		   if( document.addEventListener ){
		       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
		   }else if (document.attachEvent){
		       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
		       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
		   }
		   alert("初始化失败");
		}else{
		   onBridgeReady();
		}
	
});

//监听滑动块是否滑动到底
document.getElementById("contentBox").onscroll = function(){
	
	var divHeight = $(this).height();
	
	var scrollerTop = $(this).scrollTop();
	
	var scrollerHeight = $(this).scrollHeight();
	
	var height = scrollerTop + divHeight;
	

	if(height == scrollerHeight) {

		$.showLoading();
		
		pageIndex += 1;
		
		getMyTrips();
		
	}
	
}